using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Diagnostics;
 
namespace WindowsApplication3
{
    public class ClientThread
    {
        private Socket mySocket;
        private Thread myThread;
        private void ClientLoop()
        {
            try
            {
                ASCIIEncoding A = new ASCIIEncoding();
                mySocket.Send(A.GetBytes("Helloooooo")); 
                while (Thread.CurrentThread.IsAlive && mySocket.Connected)
                {
                    
                }
            }
            catch (ThreadAbortException)
            {

                EventLog.WriteEntry("RoboSoccer Network Layer", "Connection terminated.", EventLogEntryType.Information);
            }
            finally
            {
                mySocket.Shutdown(SocketShutdown.Both);
                mySocket.Disconnect(true);
                mySocket.Close();  
            }
        }
        public ClientThread(Socket incomingSocket)
        {
            mySocket = incomingSocket;
            myThread = new Thread(new ThreadStart(ClientLoop));
            myThread.Start();  
            EventLog.WriteEntry("RoboSoccer Network Layer", "Incoming connection accepted.", EventLogEntryType.Information);
        }
        public void Abort()
        {
            myThread.Abort();  
        }
    }
}
